﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using smp.ButterflyCakes.Repository.Databases;
using smp.ButterflyCakes.Repository.Interfaces;
using smp.QueryDb.Structure;
using smp.QueryDb.Tools;

namespace smp.ButterflyCakes.Repository.Tests
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void CreateSQlScript()
        {
            var gen = new SqlStructureGenerator();
            var tables = GetAllTables();
            Console.WriteLine(gen.GenerateCreateTableScript(tables));
        }

        private List<Table> GetAllTables()
        {
            var list = new List<Table>();
            foreach (var type in typeof(IOrderRepository).Assembly.GetTypes())
            {
                if (type.BaseType == typeof(Table))
                {
                    list.Add((Table)Activator.CreateInstance(type));
                }
            }
            return list;
        }

        //what do I want this to do...

        //scanario : load a page, make some change, saves and loads next page...

        //1. load model from db
        //2. return view and model
        //3. trigger post of updated model
        //4. save the model (domain), domain returns next stage.
        //5. load the next stage model
        //6. return the view and model

        //scenario : load a page, make a change, saves and returns same page...

        //1. load model from db
        //2. return view and model
        //3. trigger post of updated model
        //4. save the model (domain), domain returns current stage.
        //5. return the view and submitted model

        //note scenario 2 hass an added benefit, I can add model validation, and reject if model == input == view

        //complexities.
        // domain action is too much code.
        // the domain needs to do two basic things...
        //1. decide on what the next stage should be
        //2. save the changes in the model
        //3. create the next stage (if there is one).
        // currently this is two calls, I think it should be one.


        //additionally I think I should seperate the order and component into their own aggregates.

        //now an interesting thought....
        //what if instead of order and cake, I have an aggregate for each cake type?
        //the domain factory then needs to load the appropriate cake type
        //now that may be interested.

        //maybe  the problem with the domain is the contructor loading the data.
        //this adds complexity because it could fail, and I need to test it for failure.
        //got it..
        //if domain fails to load, mark itself and set a response property.
        //then on action, check and if failed return response.

        //still need to think about seperate cake or one big one for domain, specifically how to call on the model.??
        //a single interface, and a single implementation with child types to actually handle the code.

    }
}
